<?php

namespace app\admin\controller;

use app\common\service\AdminService;
use think\captcha\Captcha;
use think\Controller;

class Login extends Controller
{
    public function index()
    {
        return $this->fetch();
    }

    public function verify()
    {
        $config  = [
            // 验证码字体大小
            'fontSize' => 30,
            'fontttf'  => '4.ttf',
            // 验证码位数
            'length'   => 4,
            // 关闭验证码杂点
            'useNoise' => false,
            'useCurve' => false,
        ];
        $captcha = new Captcha($config);
        return $captcha->entry();
    }

    public function save()
    {
        $username = input('username');
        $password = input('password');
        $server   = new AdminService();
        return $server->login($username, $password);
    }

    public function logout()
    {
        session('aid', null);
        session('aname', null);
        return json(['code' => 1, 'msg' => '退出成功']);
    }
}
